package com.mszl.blog.service.impl;

import com.mszl.blog.entity.ArticleBody;
import com.mszl.blog.dao.ArticleBodyDao;
import com.mszl.blog.service.ArticleBodyService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import javax.annotation.Resource;

/**
 * (ArticleBody)表服务实现类
 *
 * @author makejava
 * @since 2025-08-03 16:02:51
 */
@Service("articleBodyService")
public class ArticleBodyServiceImpl implements ArticleBodyService {
    @Resource
    private ArticleBodyDao articleBodyDao;

    @Override
    public ArticleBody queryById(Long id) {
        return this.articleBodyDao.queryById(id);
    }

    @Override
    public Page<ArticleBody> queryByPage(ArticleBody articleBody, PageRequest pageRequest) {
        long total = this.articleBodyDao.count(articleBody);
        return new PageImpl<>(this.articleBodyDao.queryAllByLimit(articleBody, pageRequest), pageRequest, total);
    }

    @Override
    public ArticleBody insert(ArticleBody articleBody) {
        this.articleBodyDao.insert(articleBody);
        return articleBody;
    }

    @Override
    public ArticleBody update(ArticleBody articleBody) {
        this.articleBodyDao.update(articleBody);
        return this.queryById(articleBody.getId());
    }

    @Override
    public boolean deleteById(Long id) {
        return this.articleBodyDao.deleteById(id) > 0;
    }
}
